<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>收货地址管理列表</title>
<style type="text/css">	
body a{
  position: relative;
 text-decoration: none;
}
body td{
border-radius: 5px;
}
#a{
background-color:rgb(0, 128, 192);
text-align:center;

}
#b{
background-color:#ff9999;
text-align:center;
}
#s1{
width:50px;
align-items: center;
background-color:#99ffff;
border-radius: 4px;
}
#c input{
width:140px;
height:20px;
border-radius: 10px;
margin-top:10px;
}

</style>
</head>
<body>
<h1 align="center">收货地址管理列表</h1>
<div id="s2">
<input type="text" name="sousuo" id="s">&nbsp;&nbsp;&nbsp;<input type="button" value="查询" id="s1">
</div>

<br>

<%@ include file="connstring.jsp"%>
<%!
int getRecordCount(String sql,String valueField,String driver,String url){
int returnValue = 0;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{
	Class.forName(driver);
	conn=DriverManager.getConnection(url);
	stmt=conn.createStatement();
	rs=stmt.executeQuery(sql);
	if(rs.next()){
	returnValue=rs.getInt(valueField);
	}
}
catch(Exception ex){
	
}
finally{
	try{
		if(rs!=null) rs.close();
	}
	catch(SQLException ex){
	
	}
	try{
		if(stmt!=null) stmt.close();
	}
	catch(SQLException ex){
	
	}
	try{
	   if(conn!=null) conn.close();
	}
	catch(SQLException ex){
		
	} 
}
	return returnValue;
}
%>
<%
String strPageNo=request.getParameter("page");
if(strPageNo==null) strPageNo="1";
int Pagesize=6;
int curPage=Integer.parseInt(strPageNo);
int recordCount=getRecordCount("select count(id) as tiaoshu from areamanage","tiaoshu",driver,url);
int totalPage;
if(recordCount%Pagesize==0){
    totalPage=recordCount/Pagesize;
}else{
	totalPage=recordCount/Pagesize+1;
}
int startPos=Pagesize*(curPage-1);

Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{
	Class.forName(driver);
	conn = DriverManager.getConnection(url);
	stmt = conn.createStatement();
	String sql="select id,name,phone,area,types from areamanage order by id desc limit "
	+startPos+","+Pagesize+";";
	rs = stmt.executeQuery(sql);
%>
	<table width="100%" border="1" cellspacing="5" cellpadding="20">
		<tr>
			<th>ID</th>
			<th>收货人</th>
			<th>联系电话</th>
			<th>详细地址</th>
			<th>类型</th>
			<th id="t1">修改</th>
			<th id="t2">删除</th>
		</tr>
<% 
while(rs.next()){
%>
		<tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;<%=rs.getInt("id") %></td>
			<td>&nbsp;&nbsp; 
			<%=rs.getString("name") %></td>
			<td>&nbsp;&nbsp;
			<%=rs.getString("phone") %></td>
			<td>&nbsp;&nbsp;
			<%=rs.getString("area") %></td>
			<td>&nbsp;&nbsp; 
			<%=rs.getString("types") %></td>
			<td id="a"><a href="areaedit.jsp?id=<%=rs.getString("id") %>">修改</a></td>
			<td id="b"><a href="areadel.jsp?id=<%=rs.getString("id") %>"
				onclick="return confirm('你确定删除吗？');">删除</a></td>
		</tr>
<%
}
%>
	</table>
	<div class="page">
<% 
 for(int i=1;i<=totalPage;i++){
	 if(curPage==i){
	 out.print(i+"&nbsp;");
	 }
	 else
	 {
%>
		<a href="arealist.jsp?page=<%=i %>"><%=i %></a>&nbsp;
		<% 
	 }
   }
%>
		[共<%=totalPage %>页,每页<%=Pagesize %>条,共<%=recordCount %>条]
	</div>

<%
}
catch(Exception ex){
	

}finally{
 if(rs!=null) rs.close();
 if(stmt!=null)stmt.close();
 if(conn!=null) conn.close();
}
%>
</body>
</html>